package com.ruoyi.pharmacy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pharmacy.domain.vo.PharmacyOperateVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pharmacy.domain.PharmacyOperate;
import com.ruoyi.pharmacy.service.IPharmacyOperateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药房操作记录Controller
 *
 * @author ruoyi
 * @date 2025-08-22
 */
@RestController
@RequestMapping("/pharmacy/pharmacyOperate")
public class PharmacyOperateController extends BaseController
{
    @Autowired
    private IPharmacyOperateService pharmacyOperateService;

    /**
     * 查询药房操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:list')")
    @GetMapping("/list")
    public TableDataInfo list(PharmacyOperate pharmacyOperate)
    {
        startPage();
//        List<PharmacyOperate> list = pharmacyOperateService.selectPharmacyOperateList(pharmacyOperate);
        List<PharmacyOperateVo> list = pharmacyOperateService.selectPharmacyOperateVoList(pharmacyOperate);
        return getDataTable(list);
    }

    /**
     * 导出药房操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:export')")
    @Log(title = "药房操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PharmacyOperate pharmacyOperate)
    {
        List<PharmacyOperate> list = pharmacyOperateService.selectPharmacyOperateList(pharmacyOperate);
        ExcelUtil<PharmacyOperate> util = new ExcelUtil<PharmacyOperate>(PharmacyOperate.class);
        util.exportExcel(response, list, "药房操作记录数据");
    }

    /**
     * 获取药房操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:query')")
    @GetMapping(value = "/{operateId}")
    public AjaxResult getInfo(@PathVariable("operateId") Integer operateId)
    {
        return success(pharmacyOperateService.selectPharmacyOperateByOperateId(operateId));
    }

    /**
     * 新增药房操作记录
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:add')")
    @Log(title = "药房操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PharmacyOperate pharmacyOperate)
    {
        return toAjax(pharmacyOperateService.insertPharmacyOperate(pharmacyOperate));
    }

    /**
     * 修改药房操作记录
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:edit')")
    @Log(title = "药房操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PharmacyOperate pharmacyOperate)
    {
        return toAjax(pharmacyOperateService.updatePharmacyOperate(pharmacyOperate));
    }

    /**
     *  新增操作记录并更新库存
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:edit')")
    @Log(title = "药房操作记录2", businessType = BusinessType.UPDATE)
    @PutMapping("/addWithStock")
    public AjaxResult addOperateAndUpdateStock(@RequestBody PharmacyOperate pharmacyOperate )
    {
        return pharmacyOperateService.addOperateAndUpdateStock(pharmacyOperate);
    }



    /**
     * 删除药房操作记录
     */
    @PreAuthorize("@ss.hasPermi('pharmacy:pharmacyOperate:remove')")
    @Log(title = "药房操作记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operateIds}")
    public AjaxResult remove(@PathVariable Integer[] operateIds)
    {
        return toAjax(pharmacyOperateService.deletePharmacyOperateByOperateIds(operateIds));
    }


}
